﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_CompanyAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckCompany);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumBidGoods);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {

        }
    }

    protected void BtnSave_Click(object sender, EventArgs e)
    {
        int rowCun = 0;
        string AccountId_TJR, strSql;
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {
            AccountId_TJR = SysFun.ToTrim(_Account.AccountId);

            Db db = new Db();
            System.Data.IDataReader dr;
            strSql = "select count(accountid) as cun from dbo.v_account where accountname='" + SysFun.ToTrim(AccountName.Text) + "'  or dwname= '" + SysFun.ToTrim(CompanyName.Text) + "' ";
            dr = db.DataReader(strSql);
            if (dr.Read())
            {
                rowCun = SysFun.ToInt(dr["cun"]);
            }
            dr.Close();
            dr.Dispose();


            db.Close();
            if (rowCun > 0)
            {
                Response.Write("<script language=JavaScript>alert('该用户在数据库中已经存在！！！');</script>");
            }
            else
            {
                //Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
                HZ.MBSM.Model.Company Company = new HZ.MBSM.Model.Company();
                HZ.MBSM.Model.Account Account = new HZ.MBSM.Model.Account();



                if (Company != null)
                {
                    Account.AccountName = SysFun.ToTrim(AccountName.Text);
                    Account.Pwd_Bid = SysFun.PasswordEncrypt(Pwd_Bid.Text);
                    Account.Pwd_Trade = "";
                    Account.Type = Convert.ToUInt16(HZ.MBSM.DAL.AccountType.enumCompany).ToString();
                    Account.IsBid_Landing = "1";

                    Company.UserCode = SysFun.ToTrim(AccountName.Text);
                    Company.Address = "";
                    Company.RegistAddress = "";
                    Company.AreaId = SysFun.ToInt(Request.Form["AreaId"]);
                    Company.CompanyName = SysFun.ToTrim(CompanyName.Text);
                    Company.PostCode = "";
                    Company.Fax = "";
                    Company.Telepone = "";
                    Company.Lawer = "";
                    Company.IDcard = "";
                    Company.Fund = 0;
                    Company.LastIncome = 0;
                    Company.RegistDate = System.DateTime.Now;
                    Company.Email = "";
                    Company.Sort = Sort.SelectedValue;
                    Company.Introduction = "";
                    Company.NetAddress = "";
                    Company.CodeId = "";

                    Company.CodeDate = Convert.ToDateTime("1900-1-1");

                    Company.Permission = "";

                    Company.PermissionDate = Convert.ToDateTime("1900-1-1");

                    Company.IsLC = "0";
                    Company.LcLevel = "";
                    Company.LCPermission = "";

                    Company.LCDate = Convert.ToDateTime("1900-1-1");

                    Company.IsGsp = "0";
                    Company.GspCode = "";

                    Company.GspDate = Convert.ToDateTime("1900-1-1");
                    Company.GspRange = "";

                    Company.GspPermitDate = Convert.ToDateTime("1900-1-1");
                    Company.Warrant = "";

                    Company.WarrantDate = Convert.ToDateTime("1900-1-1");

                    Company.BusinessScope = "";
                    Company.memo1 = "";
                    Company.TotalFund = 0;
                    Company.FixFund = 0;
                    Company.memo3 = AccountId_TJR;
                    Company.memo5 = "";
                    Company.memo6 = "";
                    HZ.MBSM.BLL.Company_Add com = new HZ.MBSM.BLL.Company_Add();
                    if (com.CompanyAdd(Account, Company))
                    {
                        //HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "添加", "company,account", "com.CompanyAdd(Account, Company)", "../Magage/CompanyAdd.aspx");

                        Response.Write("<script>alert('保存成功！！！');</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('保存失败,请重试或与管理员联系！');</script>");
                    }

                }
                //oo.Insert(Company);

                //oo.Dispose();
                Response.Write("<script>window.opener.location.reload();window.close();</script>");

            }

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.close();</script>");
    }
}
